package com.happycat.controller;

import java.util.Date;

import com.happycat.mobile.dto.LoginDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.happycat.ResponseHeaderModel;
import com.happycat.ResponseModel;
import com.happycat.SysContants;
import com.happycat.config.HappyCatSecurity;
import com.happycat.mobile.model.UserAccount;
import com.happycat.mobile.model.UserShortMessage;
import com.happycat.mobile.service.GenerateIdService;
import com.happycat.mobile.service.UserAccountService;
import com.happycat.mobile.service.UserShortMessageService;
import com.happycat.utils.AesUtils;
import com.happycat.utils.DateUtil;
import com.happycat.utils.ResponseModelUtils;
import com.happycat.utils.SmsUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping
@Api(value = "用户登录", description = "用户登录接口")
public class LoginController {

	@Autowired
	private UserAccountService userAccountService;
	@Autowired
	private UserShortMessageService userShortMessageService;
	
	@ApiOperation(value = "获取用户状态")
	@RequestMapping(method = RequestMethod.GET, value = "/getUserStatus")
	public ResponseModel<UserAccount> getUserStatus(@RequestParam("phone") String phone) {
		
		return userAccountService.getUserStatus(phone);
	}
	@ApiOperation(value = "登录")
	@RequestMapping(method = RequestMethod.POST, value = "/login")
	public ResponseModel<UserAccount> login(@RequestBody LoginDto loginDto) {
		return userAccountService.login(loginDto);
	}

	@ApiOperation(value = "发送验证码")
	@RequestMapping(method = RequestMethod.POST, value = "/verifyCode")
	public ResponseModel<String> verifyCode(@RequestBody UserShortMessage userShortMessage) {

		return userShortMessageService.verifyCode(userShortMessage);
	}

	@ApiOperation(value = "重置密码")
	@RequestMapping(method = RequestMethod.POST, value = "/resetPassword")
	public ResponseModel<UserAccount> resetPassword(@RequestBody UserAccount userAccount) {
		return userAccountService.resetPassword(userAccount);
	}
	@ApiOperation(value = "验证短信验证码的有效性")
	@RequestMapping(method = RequestMethod.POST, value = "/checkVerifyCode")
	public ResponseModel<String> checkVerifyCode(@RequestBody UserShortMessage userShortMessage) {
		return userShortMessageService.checkVerifyCode(userShortMessage);
	}

	@ApiOperation(value = "设置密码")
	@RequestMapping(method = RequestMethod.POST, value = "/modifyPassword")
	public ResponseModel<UserAccount> modifyPassword(@RequestBody UserAccount userAccount) {
		
		return userAccountService.modifyPassword(userAccount);

	}
}
